package com.wxx;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

public class Test {

    public static void main(String[] args) throws SchedulerException {

        JobDetail jobDetail = JobBuilder.newJob(Task1.class)
                .withIdentity("Task1", "Task1Group")
                .usingJobData("wxx","pyf")
                .build();

        CronTrigger trigger = TriggerBuilder.newTrigger()
                .withIdentity("trigger1", "group1")
                .startNow()
                .withSchedule(CronScheduleBuilder.cronSchedule("0/2 * * * * ?"))
                .build();

//        JobDetail jobDetail2 = JobBuilder.newJob(Task2.class)
//                .withIdentity("Task2", "Task1Group2")
//                .usingJobData("wxx2","pyf2")
//                .build();
//
//        CronTrigger trigger2 = TriggerBuilder.newTrigger()
//                .withIdentity("trigger2", "group2")
//                .startNow()
//                .withSchedule(CronScheduleBuilder.cronSchedule("0/2 * * * * ?"))
//                .build();



        SchedulerFactory factory = new StdSchedulerFactory();
        Scheduler scheduler = factory.getScheduler();
//      程序手动关闭后，在启动会出现已经存在的问题，调用之前将之前任务给清空
        scheduler.clear();
        scheduler.scheduleJob(jobDetail,trigger);
//        scheduler.scheduleJob(jobDetail2,trigger2);
        scheduler.start();

    }
}
